package com.hzw.saas.common.util.orika;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;

import ma.glasnost.orika.MappingContext;
import ma.glasnost.orika.converter.BidirectionalConverter;
import ma.glasnost.orika.metadata.Type;

/**
 * @author EZ09
 * @since 07/20/2021
 */
public class DateTime2TimeConverter extends BidirectionalConverter<LocalDateTime, LocalTime> {

    @Override
    public LocalTime convertTo(LocalDateTime source, Type<LocalTime> destinationType, MappingContext mappingContext) {
        return source.toLocalTime();
    }

    @Override
    public LocalDateTime convertFrom(LocalTime source, Type<LocalDateTime> destinationType, MappingContext mappingContext) {
        return source.atDate(LocalDate.now());
    }
}
